package rok3.projekt.zespver3.client.objects;


import rok3.projekt.zespver3.client.Settings;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.Array;

public class TmpBullet extends Image {
	private Character source;
	private float cos_alfa;
	private float sin_alfa;
	private float speed;
	private Array<TmpBullet> controlSet;
	
	/* tmp */
	Vector2 visual_position_topleft;
	Vector2 visual_position_topright;

	Vector2 visual_position_bottomleft;
	Vector2 visual_position_bottomright;
	
	Vector2 absolute_origin;
	

	public TmpBullet(Texture texture, Character source, float pos_x,
			float pos_y, float origin_x, float origin_y, float rotation,
			float speed ) {
		super(texture);
		this.setSource(source);
		setPosition(pos_x, pos_y);
		setOrigin(origin_x, origin_y);
		this.setRotation(rotation);
		this.speed = speed;
		
		absolute_origin = new Vector2(pos_x+origin_x, pos_y + origin_y);
		visual_position_topleft=new Vector2();
		visual_position_topright=new Vector2();

		visual_position_bottomleft=new Vector2();
		visual_position_bottomright=new Vector2();
	}
	
	public void setSource(Character source) {
		this.source = source;
	}

	public Vector2 getVisualPositionTopleft() {
		visual_position_topleft.set(getX(), getY()+super.getHeight()*super.getScaleY()).sub(absolute_origin).rotate(getRotation()).add(absolute_origin);
		return visual_position_topleft;
	}
	public Vector2 getVisualPositionTopright() {
		visual_position_topright.set(getX()+super.getWidth()*super.getScaleX(), getY()+super.getHeight()*super.getScaleY()).sub(absolute_origin).rotate(getRotation()).add(absolute_origin);
		return visual_position_topright;
	}
	public Vector2 getVisualPositionBottomleft() {
		visual_position_bottomleft.set(getX(),getY()).sub(absolute_origin).rotate(getRotation()).add(absolute_origin);
		return visual_position_bottomleft;
	}
	public Vector2 getVisualPositionBottomright() {
		visual_position_bottomleft.set(getX()+super.getWidth()*super.getScaleX(), getY()).sub(absolute_origin).rotate(getRotation()).add(absolute_origin);
		return visual_position_bottomleft;
	}
	
	@Override
	public void setRotation(float degrees) {
		cos_alfa = MathUtils.cosDeg(degrees);
		sin_alfa = MathUtils.sinDeg(degrees);
		super.setRotation(degrees);
	}

	@Override
	public void act(float delta) {
		if (getX() > Settings._window_width || getY() > Settings._window_height
				|| getX() < 0 || getY() < 0) {
			this.remove();
		} else {
			float k = delta * speed;
			setPosition(getX() + cos_alfa * k, getY() + sin_alfa * k);
		}
		super.act(delta);
		absolute_origin.set(getX()+getOriginX(), getY() + getOriginY());
	}
	
}
